package org.tale.cloudbase.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * @program: boot-base
 * @author: tale-mi
 * @description:
 * @create: 2021/4/14 15:22
 **/
@RestController
@RequestMapping("discovery")
public class DiscoveryController {
    @NacosInjected
    private NamingService namingService;

    @RequestMapping(value = "/get", method = GET)
    @ResponseBody
    public List<Instance> get(@RequestParam String serviceName) throws NacosException {
        return namingService.getAllInstances(serviceName);
    }

    @RequestMapping(value = "/submit", method = POST)
    @ResponseBody
    public String submit(@RequestParam String serviceName) throws NacosException {
        return "提交成功";
    }

    @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
    @ResponseBody
    public String echo(@PathVariable String string) {
        return "Hello Nacos Discovery "+string;
    }
}
